﻿// ---------------------------------------------------------------------------------------------------------------------
//   Copyright (c) SRT Solutions 2009. All rights reserved.
// ---------------------------------------------------------------------------------------------------------------------

namespace SRTSolutions.Elevate.Guide
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;

    using NUnit.Framework;

    using SRTSolutions.Elevate;

    public class ComparableTests
    {
        [Test]
        public void EasierToRememberSyntaxForIComparables()
        {
            //with objects that implements IComparable
            var firstDate = new DateTime(1000);
            var secondDate = new DateTime(1001);

            //it can be hard to remember what
            //the int results of CompareTo mean,
            int result = firstDate.CompareTo(secondDate);
            Assert.Less(result, 0);

            //instead, you can use this syntax to make comparisons
            //easier to remmber and more readable.
            Assert.IsTrue(firstDate.LessThan(secondDate));
        }

        #region Unit Tests

        [Test]
        public void LessThanCompares()
        {
            int left = 5;
            int right = 10;
            
            Assert.IsTrue(left.LessThan(right));
            Assert.IsTrue(left.LessThanOrEqual(right));

            Assert.IsFalse(left.GreaterThan(right));
            Assert.IsFalse(left.GreaterThanOrEqual(right));
        }

        [Test]
        public void GreaterThanCompares()
        {
            int left = 55;
            int right = 10;
            
            Assert.IsTrue(left.GreaterThan(right));
            Assert.IsTrue(left.GreaterThanOrEqual(right));

            Assert.IsFalse(left.LessThan(right));
            Assert.IsFalse(left.LessThanOrEqual(right));
        }

        [Test]
        public void EqualCompares()
        {
            int left = 25;
            int right = 25;

            Assert.IsTrue(left.GreaterThanOrEqual(right));
            Assert.IsTrue(left.LessThanOrEqual(right));

            Assert.IsFalse(left.GreaterThan(right));
            Assert.IsFalse(left.LessThan(right));
        }

        // Null tests on reference types
        [Test]
        public void NullLessThanSomething()
        {
            string tmp = null;
            Assert.IsTrue(tmp.LessThan("tmp"));
        }

        [Test]
        public void SomethingNotLessThanNull()
        {
            string tmp = null;
            Assert.IsFalse("tmp".LessThan(tmp));
        }

        [Test]
        public void NullLessThanOrEqualToSomething()
        {
            string tmp = null;
            Assert.IsTrue(tmp.LessThanOrEqual("tmp"));
        }

        [Test]
        public void SomethingNotLessThanOrEqualNull()
        {
            string tmp = null;
            Assert.IsFalse("tmp".LessThanOrEqual(tmp));
        }

        [Test]
        public void NullNotGreaterThanSomething()
        {
            string tmp = null;
            Assert.IsFalse(tmp.GreaterThan("tmp"));
        }

        [Test]
        public void SomethingGreaterThanNull()
        {
            string tmp = null;
            Assert.IsTrue("tmp".GreaterThan(tmp));
        }

        [Test]
        public void NullNotGreaterThanOrEqualSomething()
        {
            string tmp = null;
            Assert.IsFalse(tmp.GreaterThanOrEqual("tmp"));
        }

        [Test]
        public void SomethingGreaterThanOrEqualNull()
        {
            string tmp = null;
            Assert.IsTrue("tmp".GreaterThanOrEqual(tmp));
        }

        [Test]
        public void NullNotLessThanNull()
        {
            string tmp = null;
            Assert.IsFalse(tmp.LessThan(null));
        }

        [Test]
        public void NullNotGreaterThanNull()
        {
            string tmp = null;
            Assert.IsFalse(tmp.GreaterThan(null));
        }

        [Test]
        public void NullLessThanEqualNull()
        {
            string tmp = null;
            Assert.IsTrue(tmp.LessThanOrEqual(null));
        }

        [Test]
        public void NullGreaterThanEqualNull()
        {
            string tmp = null;
            Assert.IsTrue(tmp.GreaterThanOrEqual(null));
        }

        #endregion

    }
}
